// -*- C++ -*-
//
//  This file is part of Siena, a wide-area event notification system.
//  See http://www.inf.usi.ch/carzaniga/siena/
//
//  Authors: Antonio Carzaniga
//  See the file AUTHORS for full details. 
//
//  Copyright (C) 2001-2003 University of Colorado
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
//  USA, or send email to one of the authors.
//
//
// $Id: bool_index.h,v 1.11 2010-03-11 15:16:39 carzanig Exp $
//
#ifndef BOOL_INDEX_H
#define BOOL_INDEX_H

#include "siena/forwarding.h"
#include "siena/allocator.h"

#include "fwd_table.h"

namespace siena {

/** index for <em>equals</em> constraints on boolean attributes **/
class BoolIndex {
public:
				BoolIndex() throw();

    ConstraintType *		add_any(FTAllocator &) throw();
    ConstraintType *		add_ne(bool v, FTAllocator &) throw();
    ConstraintType *		add_eq(bool v, FTAllocator &) throw();
    bool			match(bool v, CProcessor & p) const throw();

 private:
    ConstraintType * any_value;
    ConstraintType * t;
    ConstraintType * f;
};

inline BoolIndex::BoolIndex() throw ()
    : any_value(0), t(0), f(0) {}

inline bool BoolIndex::match(bool v, CProcessor & p) const throw() {
    if (any_value != 0) 
	if (p.process_constraint(any_value))
	    return true;
    if (v) {
	if (t != 0) return p.process_constraint(t);
    } else {
	if (f != 0) return p.process_constraint(f);
    }
    return false;
}

} // end namespace siena

#endif
